package com.activities;

import java.util.ArrayList;

import com.example.lizhiinformation.R;
import com.myadapter.CommentAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
/**
 *评论界面2
 */
public class Comment extends Activity {

	private EditText content;
	private TextView send;
	private ListView listview;
	private String text=null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_comment);
		Button back = (Button) findViewById(R.id.comment_back);
		send = (TextView) findViewById(R.id.comment_title);
		content = (EditText) findViewById(R.id.conntent);
		
		listview = (ListView) findViewById(R.id.contentlistview);
		final ArrayList<String> list=new ArrayList<String>();
		final CommentAdapter adapter = new CommentAdapter(list, Comment.this);
		listview.setAdapter(adapter);
		content.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				if(content.getText().toString()!=null){
				text=content.getText().toString();
				}
				
			}
		});
		send.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(text!=null){
					list.add(text);
					adapter.add(list);
					content.setText(null);
				}else{
					Toast.makeText(Comment.this, "评论内容不能为空", 1).show();
					content.setText(null);
					
				}
				list.clear();
				text=null;
			}
		});
		
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Comment.this.finish();
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.comment, menu);
		return true;
	}

}
